package com.zhan.ielts.dao.impl.article;

import com.zhan.frame.core.dao.impl.BaseDaoImpl;
import com.zhan.ielts.dao.article.ArticleDao;
import com.zhan.ielts.domain.article.Article;
import com.zhan.ielts.domain.article.query.ArticleQuery;
import com.zhan.ielts.domain.article.vo.ArticleVo;
import com.zhan.ielts.domain.article.vo.HotArticleVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2016/8/19.
 */
@Repository
public class ArticleDaoImpl extends BaseDaoImpl<Article> implements ArticleDao {

    @Override
    public void insertBatchArticles(List<Article> articleList) {
        sqlSessionTemplate.insert(getSqlName("insertBatch"), articleList);
    }

    @Override
    public void insertHotArticle(HotArticleVo hotArticleVo) {
        sqlSessionTemplate.update(getSqlName("insertHotArticle"), hotArticleVo);
    }

    @Override
    public Page<ArticleVo> queryArticleVoPageList(ArticleQuery query, Pageable pageable) {
        List<ArticleVo> contentList = sqlSessionTemplate.selectList(getSqlName("selectVo"),
                getParams(query, pageable));
        return new PageImpl<ArticleVo>(contentList, pageable, this.selectCount(query));
    }
}
